<% @view_title = "Edit Template" -%>

<div class="admin_workspace">
    <%= form_for(@pipeline, :as => :template, :url => update_template_permissions_path(:template_name => @pipeline.name().toString()), :html => {:method => "post", :id => "template_edit_form"}) do |f| %>

        <div class="form_content">
            <h3>Basic Settings</h3>

            <div class="fieldset">
                <%= md5_field %>
                <%= f.label com.thoughtworks.go.config.PipelineTemplateConfig::NAME, 'Template Name' -%>
                <%= f.text_field com.thoughtworks.go.config.PipelineTemplateConfig::NAME, :readonly => :readonly, :disabled=> :disabled -%>
                <%= error_message_on(@pipeline, com.thoughtworks.go.config.PipelineTemplateConfig::NAME, :css_class => "form_error") %>
                <div class="clear"></div>
            </div>

          <div class="permissions">
            <h3> User Permissions </h3>
            <div class="allow">
              <%= f.check_box com.thoughtworks.go.config.Authorization::ALLOW_GROUP_ADMINS, {:class => "form_input"}, "true", "false" %>
              <label class="inline">Allow all pipeline group administrators view access to <%= @pipeline.name %> template.</label>
            </div>
            <div class="fieldset user_permissions_for_template">
              <%= render :partial => 'permissions_table',
                         :locals => {:scope => {:permissions => @pipeline.getAuthorization().getUserAuthorizations(), :permission_type => com.thoughtworks.go.config.Authorization::UserType::USER, :f => f, :autocomplete_suggestions => @autocomplete_users}} %>
              <div class="clear"></div>
            </div>
            <h3> Role Permissions </h3>
            <div class="fieldset role_permissions_for_template">
              <%= render :partial => 'permissions_table',
                         :locals => {:scope => {:permissions => @pipeline.getAuthorization().getRoleAuthorizations(), :permission_type => com.thoughtworks.go.config.Authorization::UserType::ROLE, :f => f, :autocomplete_suggestions => @autocomplete_roles}} %>
              <div class="clear"></div>
            </div>
          </div>
        </div>
        <%= render :partial => "admin/shared/form_submit", :locals => {:scope => {:reset_url => edit_template_permissions_path(:template_name => @pipeline.name().toString())}} %>
    <% end %>
</div>
<script type="text/javascript">
  Util.on_load(function() {
    var groupPermissions = new GroupPermissions("<%=com.thoughtworks.go.config.Authorization::PrivilegeState::ON-%>",
      "<%=com.thoughtworks.go.config.Authorization::PrivilegeState::OFF-%>",
      "<%=com.thoughtworks.go.config.Authorization::PrivilegeState::DISABLED-%>");

    groupPermissions.bindFromHiddenField();
    groupPermissions.bindHandlers();
  });
</script>

<%= render :partial => "admin/shared/dirty_form", :locals => {:scope => {:form_id => 'template_edit_form', :reset_id => "reset_form"}} %>
<%= render :partial => 'shared/convert_tool_tips.html', :locals => {:scope => {}} %>
